package cn.mugutu.finance.domain.system;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

@Entity
@Table(name = "sys_menu")
@Data
public class Menu implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    //	@GeneratedValue   //由于系统菜单是手动初始化,所以这里不是自增长
    private Long id;
    @Column(unique = true)
    private String name;
    private String url;
    private String icon;

    @ManyToOne
    @JoinColumn(name = "parentId")
    @JSONField(serialize = false)
    private Menu parent;

    @OneToMany(mappedBy = "parent")
    private List<Menu> children = new ArrayList<>();


    @Override
    public String toString() {
        return "Menu [id=" + id + ", name=" + name + ", url=" + url + ", icon=" + icon + "]";
    }

}
